﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DataAccess;
namespace QuanLyDiemSV
{
    public partial class QLKeHoachThi : System.Web.UI.Page
    {
        ketnoi kn = new ketnoi();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                load();
            }
        }
        string malop = "L01";
        private void load()
        {
            GridView1.DataSource = BUS.QLKeHoachThi.xemkehoachthi(Session["malopdoclap"].ToString());
            GridView1.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox txtmasv = (TextBox)GridView1.FooterRow.FindControl("txtmasv");
            TextBox txthoten = (TextBox)GridView1.FooterRow.FindControl("txthoten");
            TextBox txtdiem1 = (TextBox)GridView1.FooterRow.FindControl("txtdiem1");
            TextBox txtdiem2 = (TextBox)GridView1.FooterRow.FindControl("txtdiem2");
            string masv = txtmasv.Text;
            string hoten = txthoten.Text;
            float diem1 = float.Parse(txtdiem1.Text);
            float diem2 = float.Parse(txtdiem2.Text);
            string kq = kn.update("insert into DiemThi values('" + masv + "','" + hoten + "','" + diem1 + "','" + diem2 + "')");
            //string kq=BUS.QLDiemThi.update(masinhvien)
            if (kq != "")
            {
                Response.Write("<script>alert('ban them thanh cong');</script");
                load();

            }
            else
            {
                Response.Write("<script>alert('ban them that bai');</script");
            }

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string masv = e.Values["MaSinhVien"].ToString();
            string kq = kn.update("delete from DiemThi where MaSinhVien = " + masv);
            if (kq != "")
            {
                Response.Write("<script>alert('ban xoa thanh cong');</script");
                load();

            }
            else
            {
                Response.Write("<script>alert('ban xoa that bai');</script");
            }
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            load();

        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string malop = e.NewValues["MaLop"].ToString();
            string ngaythi =e.NewValues["NgayThi"].ToString();
            string cathi =e.NewValues["CaThi"].ToString();
            string lanthi =e.NewValues["LanThi"].ToString();
            //string kq = kn.update("update DiemThi set DiemThiLan1='" + diem1 + "',DiemThiLan2='"+diem2+"' where MaSinhVien='" + masv + "'");
            string kq = BUS.QLKeHoachThi.update(malop,ngaythi,cathi,lanthi).ToString();
            //string kq = BUS.QLDiemTrenLop.update("M01", masv, "HK01", diem1, diem2, diem3, diem4, diem5, diemgiuahocphan, diemchuyencan, diemtrungbinh, sotietnghi, dieukienthi);
            if (kq != "")
            {
                Response.Write("<script>alert('ban update thanh cong');</script");
                GridView1.EditIndex = -1;
                load();
            }
            else
            {
                Response.Write("<script>alert('ban update that bai');</script");
            }
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            load();
        }

    }

}